/*
 * Copyright (C) 2010-2011 Comcast Cable.  All Rights Reserved.
 */
package com.hercules.android.receiver.model.events;

/**
 * <p>
 * This is a subclass of XREEvent that represents the "onHTTPResponse" event. It defines some properties specific to
 * this event. Note that values of all custom properties are actually stored in the XREEvent#params map.
 * </p>
 * <p>
 * <strong>Thread safety:</strong> This class is mutable and not thread safe.
 * </p>
 *
 * @author saarixx, jmn
 * @version 1.0
 */
public class XREApplicationHTTPResponseEvent extends XREApplicationEvent {

    /**
     * <p>
     * Represents the name of the "on HTTP response" event.
     * </p>
     * <p>
     * This is a string constant used by the user when setting the name of the event.
     * </p>
     */
    public static final String ON_HTTP_RESPONSE_EVENT_NAME = "onHTTPResponse";

    /**
     * <p>
     * Represents the name used to retrieve the status parameter.
     * </p>
     */
    private static final String STATUS = "status";

    /**
     * <p>
     * Represents the name used to retrieve the content type parameter.
     * </p>
     */
    private static final String CONTENT_TYPE = "contentType";

    /**
     * <p>
     * Represents the name used to retrieve the body parameter.
     * </p>
     */
    private static final String BODY = "body";

    /**
     * <p>
     * Creates new instance of {@link XREApplicationHTTPResponseEvent} class.
     * </p>
     */
    public XREApplicationHTTPResponseEvent() {
        // empty constructor
    }

    /**
     * <p>
     * Retrieves the HTTP status code of the response.
     * </p>
     * <p>
     * AndroidAssembly2 changed to integer
     *
     * @return the HTTP status code of the response
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    @SuppressWarnings("boxing")
    public int getStatus() {

        return getTypedParam(STATUS, Integer.class);
    }

    /**
     * <p>
     * Sets the HTTP status code of the response.
     * </p>
     * <p>
     * AndroidAssembly2 changed to integer
     *
     * @param status the HTTP status code of the response
     * @throws IllegalStateException if params is null
     */
    @SuppressWarnings("boxing")
    public void setStatus(int status) {
        setParam(STATUS, status);
    }

    /**
     * <p>
     * Retrieves the Content-Type as returned in the HTTP response.
     * </p>
     *
     * @return the Content-Type as returned in the HTTP response
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public String getContentType() {

        return getTypedParam(CONTENT_TYPE, String.class);
    }

    /**
     * <p>
     * Sets the Content-Type as returned in the HTTP response.
     * </p>
     *
     * @param contentType the Content-Type as returned in the HTTP response
     * @throws IllegalStateException if params is null
     */
    public void setContentType(String contentType) {

        setParam(CONTENT_TYPE, contentType);
    }

    /**
     * <p>
     * Retrieves the Base-64 encoded body of the HTTP response.
     * </p>
     *
     * @return the Base-64 encoded body of the HTTP response
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public String getBody() {

        return getTypedParam(BODY, String.class);
    }

    /**
     * <p>
     * Sets the Base-64 encoded body of the HTTP response.
     * </p>
     *
     * @param body the Base-64 encoded body of the HTTP response
     * @throws IllegalStateException if params is null
     */
    public void setBody(String body) {

        setParam(BODY, body);
    }
}
